package com.xique.park.controller.client.web.controller;

import com.xique.common.core.utils.poi.ExcelUtil;
import com.xique.common.core.web.controller.BaseController;
import com.xique.common.core.web.domain.AjaxResult;
import com.xique.common.core.web.page.TableDataInfo;
import com.xique.common.log.annotation.Log;
import com.xique.common.log.enums.BusinessType;
import com.xique.common.security.annotation.PreAuthorize;
import com.xique.park.controller.client.web.bean.domain.OpengateRecords;
import com.xique.park.controller.client.web.service.service.IOpengateRecordsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;

/**
 * 开关闸记录Controller
 *
 * @author xique
 * @date 2022-01-13
 */
@RestController
@RequestMapping("/records")
public class OpengateRecordsController extends BaseController
{
    @Autowired
    private IOpengateRecordsService opengateRecordsService;

    /**
     * 查询开关闸记录列表
     */
    @PreAuthorize(hasPermi = "park:records:list")
    @GetMapping("/list")
    public TableDataInfo list(OpengateRecords opengateRecords)
    {
        startPage();
        List<OpengateRecords> list = opengateRecordsService.selectOpengateRecordsList(opengateRecords);
        return getDataTable(list);
    }

    /**
     * 导出开关闸记录列表
     */
    @PreAuthorize(hasPermi = "park:records:export")
    @Log(title = "开关闸记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, OpengateRecords opengateRecords) throws IOException
    {
        List<OpengateRecords> list = opengateRecordsService.selectOpengateRecordsList(opengateRecords);
        ExcelUtil<OpengateRecords> util = new ExcelUtil<OpengateRecords>(OpengateRecords.class);
        util.exportExcel(response, list, "开关闸记录数据");
    }

    /**
     * 获取开关闸记录详细信息
     */
    @PreAuthorize(hasPermi = "park:records:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(opengateRecordsService.selectOpengateRecordsById(id));
    }

    /**
     * 新增开关闸记录
     */
    @PreAuthorize(hasPermi = "park:records:add")
    @Log(title = "开关闸记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody OpengateRecords opengateRecords)
    {
        return toAjax(opengateRecordsService.insertOpengateRecords(opengateRecords));
    }

    /**
     * 修改开关闸记录
     */
    @PreAuthorize(hasPermi = "park:records:edit")
    @Log(title = "开关闸记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody OpengateRecords opengateRecords)
    {
        return toAjax(opengateRecordsService.updateOpengateRecords(opengateRecords));
    }

    /**
     * 删除开关闸记录
     */
    @PreAuthorize(hasPermi = "park:records:remove")
    @Log(title = "开关闸记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        List<Long> idList = Arrays.asList(ids);
        return toAjax(opengateRecordsService.deleteOpengateRecordsByIds(idList));
    }
}
